package com.gewu.pm.ui.adapter.order;

import android.content.Context;
import android.view.ViewGroup;
import android.widget.TextView;

import androidx.annotation.NonNull;

import com.gewu.pm.R;
import com.gewu.pm.app.AppAdapter;
import com.gewu.pm.bean.TelegraphicTransferBean;

/**
 * 电汇收款适配器
 */
public final class TelegraphicTransferAdapter extends AppAdapter<TelegraphicTransferBean> {

    public TelegraphicTransferAdapter(Context context) {
        super(context);
    }

    @NonNull
    @Override
    public ViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        return new ViewHolder();
    }

    private final class ViewHolder extends AppAdapter<?>.ViewHolder {

        private final TextView tvTerminalName;
        private final TextView tvStatus;
        private final TextView tvSubmitter;
        private final TextView tvSubmitTime;
        private final TextView tvDocumentNo;
        private final TextView tvPaymentMethod;
        private final TextView tvAmount;

        private ViewHolder() {
            super(R.layout.telegraphic_transfer_item);
            tvTerminalName = findViewById(R.id.tv_terminal_name);
            tvStatus = findViewById(R.id.tv_status);
            tvSubmitter = findViewById(R.id.tv_submitter);
            tvSubmitTime = findViewById(R.id.tv_submit_time);
            tvDocumentNo = findViewById(R.id.tv_document_no);
            tvPaymentMethod = findViewById(R.id.tv_payment_method);
            tvAmount = findViewById(R.id.tv_amount);
        }

        @Override
        public void onBindView(int position) {
            TelegraphicTransferBean bean = getItem(position);
            tvTerminalName.setText(bean.getTerminalName());
            tvStatus.setText(bean.getStatus());
            tvSubmitter.setText(bean.getSubmitter());
            tvSubmitTime.setText(bean.getSubmitTime());
            tvDocumentNo.setText(bean.getDocumentNo());
            tvPaymentMethod.setText(bean.getPaymentMethod());
            tvAmount.setText(bean.getAmount());

            // 根据状态设置不同的样式
            setStatusStyle(bean.getStatus());
        }

        /**
         * 设置状态标签样式
         */
        private void setStatusStyle(String status) {
            if ("待审批".equals(status)) {
                tvStatus.setTextColor(getResources().getColor(R.color.red_app));
                tvStatus.setBackgroundResource(R.drawable.shape_label_red);
            } else if ("已通过".equals(status)) {
                tvStatus.setTextColor(getResources().getColor(R.color.green_label));
                tvStatus.setBackgroundResource(R.drawable.shape_green_stroke_corner);
            } else if ("已作废".equals(status)) {
                tvStatus.setTextColor(getResources().getColor(R.color.cb9));
                tvStatus.setBackgroundResource(R.drawable.shape_gray_stroke_corner);
            }
        }
    }
}

